package com.aier.admin.common;

import com.aier.common.common.Constant;

public class AdminUtil {

    /**
     * 自动补全固定长度字符串
     * @param strSrc 原始字符串
     * @param flag 要补的字符
     * @param strSrcLength 需要长度
     * @return
     */
    public static String leftPading(String strSrc, String flag, int strSrcLength) {
        String strReturn = "";
        String strtemp = "";
        int curLength = strSrc.trim().length();
        if (strSrc != null && curLength > strSrcLength) {
            strReturn = strSrc.trim().substring(0, strSrcLength);
        } else if (strSrc != null && curLength == strSrcLength) {
            strReturn = strSrc.trim();
        } else {

            for (int i = 0; i < (strSrcLength - curLength); i++) {
                strtemp = strtemp + flag;
            }

            strReturn = strtemp + strSrc.trim();
        }
        return strReturn;
    }
    
    /**
     * 判断是否是中文
     * @param strSrc 原始字符串
     * @param flag 要补的字符
     * @param strSrcLength 需要长度
     * @return
     */
    
    public static boolean check(String str){
          
        char[] chars=str.toCharArray(); 
        boolean isGB2312=false; 
        for(int i=0;i<chars.length;i++){
            byte[] bytes=(""+chars[i]).getBytes(); 
            if(bytes.length==2){ 
                int[] ints=new int[2]; 
                ints[0]=bytes[0]& Constant.num_ff; 
                ints[1]=bytes[1]& Constant.num_ff; 
                if(ints[0]>=Constant.num_0x81 && ints[0]<=Constant.num_fe && ints[1]>=Constant.num_0x40 && ints[1]<=Constant.num_fe){ 
                    isGB2312=true; 
                    break; 
                } 
            } 
        } 
        return isGB2312; 
    }

    
}
